define(function(){
    var getUrlParam = function(name){
        var r = window.location.href;
        var reg = new RegExp('/'+name+'/[^/]*');
        var res = r.match(reg);
        if(res){
            res = res[0].split('/');
            return unescape(res[res.length-1]);
        }else{
            return null;
        }
    }
    var setSession = function(name,value){
        window.sessionStorage.setItem(name,value)
    }
    var getSession = function(name){        
        return window.sessionStorage.getItem(name);
    }
    var footer = function(tab){
        var data = '<footer>' +
            '<ul class="footer">' +
            '<li>' +
            '<a href="'+MODULE+'PublicJump/media_index">' +
            '<div class="icon_box">'
        tab == 1 ? data += '<img src="'+PUBLIC+'img/public/red-media.png" alt="全媒体"></div><p class="media-Option active">全媒体</p>': data += '<img src="'+PUBLIC+'img/public/media.png" alt="全媒体"></div><p class="media-Option">全媒体</p>';
        data += '</a>' +
            ' </li>' +
            '<li>' +
            '<a href="'+MODULE+'PublicJump/shopmall_index/shopmall/1">' +
            '<div class="icon_box">'

        tab == 2 ? data += '<img src="'+PUBLIC+'img/public/red-county.png" alt="县会长"></div><p class="media-Option active">县会长</p>': data += '<img src="'+PUBLIC+'img/public/county.png" alt="县会长"></div><p class="media-Option">县会长</p>';
        data += '</a>' +
            ' </li>' +
            '<li>' +
            '<a href="'+MODULE+'PublicJump/shopmall_index/shopmall/2">' +
            '<div class="icon_box">'

        tab == 3 ? data += '<img src="'+PUBLIC+'img/public/red-area.png" alt="一带一路"></div><p class="media-Option active">一带一路</p>': data += '<img src="'+PUBLIC+'img/public/area.png" alt="一带一路"></div><p class="media-Option">一带一路</p>';
        data += '</a>' +
            ' </li>' +
            '<li>' +
            '<a href="'+MODULE+'PublicJump/global_index">' +
            '<div class="icon_box">'

        tab == 4 ? data += '<img src="'+PUBLIC+'img/public/red-global.png" alt="全球购"></div><p class="media-Option active">全球购</p>': data += '<img src="'+PUBLIC+'img/public/global.png" alt="全球购"></div><p class="media-Option">全球购</p>';
        data += '</a>' +
            ' </li>' +
            '</ul>' +
            '</footer>'
       $("body").append(data).css("padding-bottom","72px");
    };
    var header = function(){
        var data = ' <header class="head">' +
            '        <div class="project_header">' +
            '            <div class="icon_box fl back_icon_box">' +
            '                <img src="'+PUBLIC+'img/public/back.png" alt="返回">\n' +
            '            </div>' +
            '            <div class="header_center">' +
            '                <div class=" icon_box fl">' +
            '                    <img src="'+PUBLIC+'img/public/search.png" alt="">\n' +
            '                </div>\n' +
            '                <input class="header_center_search toSearch fl" type="text" placeholder="请输入搜索内容">\n' +
            '            </div>\n' +
            '            <div class="more_box icon_box fr">\n' +
            '                    <img src="'+PUBLIC+'img/public/more.png" alt="更多">\n' +
            '            </div>\n' +
            '        </div>\n' +
            '    </header>';
        $("body").append(data).css("padding-top","50px");
        $('.header_center').on('click mousedown','.toSearch',function(){
            window.location.href = MODULE + 'PublicJump/search';
        });
        $('.project_header').on('click','.back_icon_box',function(){
            window.history.go(-1);
        });
        $('.project_header').on('click','.more_box',function(){
            if($(this).find('img').data('url')){
                window.location.href = $(this).find('img').data('url')
            }else{
                window.location.href = MODULE+ 'PublicJump/search';
            }
        });
    };
    var headertitle = function(title,url){
        var data = ' <header class="release">\n' +
            '         <div class="project_header project_header1 ">' +
            '             <div class=" icon_box fl back_icon_box">' +
            '                <img src="'+PUBLIC+'img/public/back.png" alt="返回">\n' +
            '            </div>' +
            '            <h3 class="project_header_title">'+ title +'</h3>\n' +
            '           <div class=" more_box icon_box fr">\n' +
            '                <img src="'+PUBLIC+(url?'img/public/add.png" data-url="'+url:'img/public/more.png')+'" alt="添加">\n' +
            '            </div>\n' +
            '        </div>\n' +
            '    </header>';
        $("body").append(data).css("padding-top","50px");
        $('.project_header').on('click','.back_icon_box',function(){
            window.history.go(-1);
        });
        $('.project_header').on('click','.more_box',function(){
            if($(this).find('img').data('url')){
                window.location.href = $(this).find('img').data('url')
            }else{
                window.location.href = MODULE+ 'PublicJump/search';
            }
        });
    }
    var allocator = function(){
        var width = $(window).width();
        $('html').css('font-size',width/640*100+'px !important');
    }
    var loaded = function(){
        $('body').addClass('loaded');
        $('.loading-dialog').addClass('hide');
    }
    //必须注册才能访问的页面黑名单
    if(!getSession('token') && window.location.href.search(/(personal|personalInfo|productAdd|productEdit|releaseAdd|releaseEdit|myFav|myOrder|myRelease|myProduct|manage)/) >= 0){
        console.log('请登录');
        window.location.replace(MODULE+'PublicJump/sign');
    }else if(getSession('token') && window.location.href.search(/sign|register/) >= 0){
        console.log('已经登录');
        window.location.replace(MODULE+'PublicJump/media_index');
    }
    return{
        footer:footer,
        header:header,
        headertitle:headertitle,
        allocator: allocator,
        getUrlParam: getUrlParam,
        loaded: loaded,
        getSession: getSession,
        setSession: setSession,
    };
})
